home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / pyshared / Onboard / KbdWindow.py < prev    next >
Text File  |  2009-10-01  |  6KB  |  190 lines

  1. import gtk
  2. import gobject
  3.  
  4. from Onboard.IconPalette import IconPalette
  5.  
  6. ### Logging ###
  7. import logging
  8. _logger = logging.getLogger("KbdWindow")
  9. ###############
  10.  
  11. ### Config Singleton ###
  12. from Onboard.Config import Config
  13. config = Config()
  14. ########################
  15.  
  16. class KbdWindow(gtk.Window):
  17.     """Very messy class holds the keyboard widget.  The mess is the docked window support which is disable because of numerous metacity bugs."""
  18.     def __init__(self):
  19.         gtk.Window.__init__(self)
  20.         _logger.debug("Entered in __init__")
  21.         self.keyboard = None
  22.         self.connect("destroy", gtk.main_quit)
  23.         self.connect("configure-event", self.cb_configure_event)
  24.         self.set_accept_focus(False)
  25.         self.grab_remove()
  26.         self.set_keep_above(True)
  27.         self.hidden = True
  28.  
  29.         config.geometry_notify_add(self.resize)
  30.         self.set_default_size(config.keyboard_width, config.keyboard_height)
  31.         config.position_notify_add(self.move)
  32.         self.move(config.x_position, config.y_position)
  33.  
  34.         self.connect("window-state-event", self.cb_state_change)
  35.  
  36.         self.icp = IconPalette()
  37.         self.icp.connect("activated", self.do_show)
  38.         config.icp_in_use_change_notify_add(self._on_icp_in_use_toggled)
  39.         _logger.debug("Leaving __init__")
  40.  
  41.     def move(self, new_x_position, new_y_position):
  42.         # Don't move window if already in the right place.
  43.         x_position, y_position = self.get_position()
  44.         if x_position != new_x_position or y_position != new_y_position:
  45.             gtk.Window.move(self, new_x_position, new_y_position)
  46.  
  47.     def do_show(self, widget=None):
  48.         _logger.debug("Entered in do_show")
  49.         self.icp.do_hide()
  50.         self.move(config.x_position, config.y_position) # to be sure that the window manager places it correctly
  51.         self.show_all()
  52.         self.hidden = False
  53.         _logger.debug("Leaving do_show")
  54.  
  55.     def do_hide(self):
  56.         _logger.debug("Entered in do_hide")
  57.         self.hide_all()
  58.         self.hidden = True
  59.         if config.icp_in_use: self.icp.do_show()
  60.         _logger.debug("Leaving do_hide")
  61.  
  62.     def set_keyboard(self, keyboard):
  63.         _logger.debug("Entered in set_keyboard")
  64.         if self.keyboard:
  65.             self.remove(self.keyboard)
  66.         self.keyboard = keyboard
  67.         self.add(self.keyboard)
  68.         self.keyboard.show()
  69.         self.queue_draw()
  70.  
  71.     def do_set_layout(self, client, cxion_id, entry, user_data):
  72.         _logger.debug("Entered in do_set_layout")
  73.         return
  74.  
  75.     def cb_configure_event(self, event, user_data):
  76.         """
  77.         Callback that is called when onboard receives a configure-event
  78.         because of a change of its position or size.
  79.         The callback stores the new values to the correspondent gconf
  80.         keys.
  81.         """
  82.         _logger.debug("Entered in cb_configure_event")
  83.         x_pos, y_pos = self.get_position()
  84.         width, height = self.get_size()
  85.  
  86.         # store new value only if it is different to avoid infinite loop
  87.         config.x_position = x_pos
  88.         config.y_position = y_pos
  89.         config.keyboard_width = width
  90.         config.keyboard_height = height
  91.  
  92.  
  93.     def do_set_gravity(self, edgeGravity):
  94.         _logger.debug("Entered in do_set_gravity")
  95.         self.edgeGravity = edgeGravity
  96.         width, height = self.get_size()
  97.  
  98.         '''
  99.         This will place the window on the edge corresponding to the edge gravity
  100.         '''
  101.  
  102.         geom = self.get_screen().get_monitor_geometry(0)
  103.         eg = self.edgeGravity
  104.  
  105.         x = 0
  106.         y = 0
  107.         if eg == gtk.gdk.GRAVITY_SOUTH:
  108.             y = geom.height - height
  109.             y += 29 #to account for panel.
  110.  
  111.  
  112.         self.move(x, y)
  113.  
  114.         gobject.idle_add(self.do_set_strut)
  115.  
  116.     def do_set_strut(self):
  117.         _logger.debug("Entered in do_set_strut")
  118.         propvals = [0,0,0,0,0,0,0,0,0,0,0,0]
  119.         """propvals = [0,#left
  120.                 0, #right
  121.                 0, #top
  122.                 300,#bottom
  123.                 0,#left_start_y
  124.                 0,#left_end_y
  125.                 0,#right_start_y
  126.                 0,#right_end_y
  127.                 0,#top_start_x
  128.                 0,#top_end_x
  129.                 0,#bottom_start_x
  130.                 3000]#bottom_end_x"""
  131.  
  132.         screen = self.get_screen()
  133.         biggestHeight = 0
  134.         for n in range(screen.get_n_monitors()):
  135.             tempHeight = screen.get_monitor_geometry(n).height
  136.             if biggestHeight < tempHeight:
  137.                 biggestHeight = tempHeight
  138.  
  139.         geom = self.get_screen().get_monitor_geometry(0)
  140.         eg = self.edgeGravity
  141.         x, y = self.window.get_origin()
  142.  
  143.         width,height = self.get_size()
  144.  
  145.         if eg == gtk.gdk.GRAVITY_NORTH:
  146.             propvals[2] = height + y
  147.             propvals[9] = width
  148.         elif eg == gtk.gdk.GRAVITY_SOUTH and y != 0:
  149.             #propvals[2] = y
  150.             #propvals[9] = geom.width - 1
  151.             propvals[3] = biggestHeight - y
  152.             propvals[11] = width - 1
  153.  
  154.         # tell window manager to not overlap buttons with maximized window
  155.             self.window.property_change("_NET_WM_STRUT_PARTIAL",
  156.                                         "CARDINAL",
  157.                                         32,
  158.                                         gtk.gdk.PROP_MODE_REPLACE,
  159.                                         propvals)
  160.         self.queue_resize_no_redraw()
  161.  
  162.  
  163.     def cb_state_change(self, widget, event):
  164.         """
  165.         This is the callback that gets executed when the user hides the
  166.         onscreen keyboard by using the minimize button in the decoration
  167.         of the window.
  168.         """
  169.         _logger.debug("Entered in cb_state_change")
  170.         if event.changed_mask & gtk.gdk.WINDOW_STATE_ICONIFIED:
  171.             if event.new_window_state & gtk.gdk.WINDOW_STATE_ICONIFIED:
  172.                 self.do_hide()
  173.                 self.deiconify()
  174.  
  175.     def _on_icp_in_use_toggled(self, icp_in_use):
  176.         """
  177.         This is the callback that gets executed when the user toggles 
  178.         the gconf key named in_use of the icon_palette.
  179.         """
  180.         _logger.debug("Entered in _on_icp_in_use_toggled")
  181.         if not self.hidden:
  182.             _logger.debug("Entered in not self.hidden")
  183.             return
  184.         elif icp_in_use:
  185.             _logger.debug("calling do_show")
  186.             self.icp.do_show()
  187.         else:
  188.             _logger.debug("calling do_hide")
  189.             self.icp.do_hide()
  190.